# -*- coding:utf-8 -*-
# /testdata_syncer_client.py    测试数据同步脚本

import socket
import os
import config
import datetime


def test_data_syncer_delete_data(problem_id):
    client = socket.socket()
    client.connect((config.testdata_syncer_host, config.testdata_syncer_port))
    print("[%s] 发送删除数据任务 #%s" % (datetime.datetime.now(), problem_id))
    client.sendall(("del," + str(problem_id)).encode())


def test_data_syncer_upload_data(file_name):
    client = socket.socket()
    client.connect((config.testdata_syncer_host, config.testdata_syncer_port))
    print("[%s] 发送上传数据任务" % (datetime.datetime.now()))
    client.sendall("upl,".encode())
    file_size = os.stat(file_name).st_size
    has_sent = 0
    with open(file_name, "rb") as f:
        while has_sent != file_size:
            data = f.read(1024)
            client.sendall(data)
            has_sent += len(data)
    print("[%s] 上传数据完成" % (datetime.datetime.now()))
